<?php

namespace app\admin\validate\company;

use ShidianUtil\Thinkphp\Validate\BaseValidate;
use ShidianUtil\Utils\CheckUtil;

/**
 * Class Personnel
 * @package app\admin\validate\company
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037623
 * @see \app\admin\controller\company\Personnel
 */
class Personnel extends BaseValidate
{

    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id' => 'isId',
        'companyId' => 'integer|egt:0|max:10',
        'name' => 'scalar|max:12',
        'mobile' => 'phone|max:16',
        'desc' => 'scalar|max:255',
        'quotaCard' => 'numeric|egt:0',
        'quotaCoin' => 'numeric|egt:0',
        'updated' => 'integer|egt:0|max:11',
        'created' => 'integer|egt:0|max:11',
        'deleted' => 'integer|egt:0|max:11',
        'page' => 'integer|egt:0|max:11',
        'page_size' => 'integer|egt:0|max:11',
    ];

    protected $field = [
        'id' => 'id',
        'companyId' => '所属公司',
        'name' => '员工姓名',
        'mobile' => '手机号',
        'desc' => '员工备注',
        'quotaCard' => '获客卡限额/天',
        'quotaCoin' => '通信币限额/天',
        'page' => '分页页数',
        'page_size' => '分页大小',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.require' => '缺少:attribute',
        'id.isId' => '请设置正确的:attribute',
        'companyId.require' => '请输入:attribute',
        'companyId.integer' => ':attribute应该是整数',
        'companyId.egt' => ':attribute应该大于等于:rule',
        'companyId.max' => ':attribute长度不能超过:rule位',
        'name.require' => '请输入:attribute',
        'name.scalar' => ':attribute应该是字符串',
        'name.max' => ':attribute长度不能超过:rule位',
        'mobile.require' => '请输入:attribute',
        'mobile.scalar' => ':attribute应该是字符串',
        'mobile.max' => ':attribute长度不能超过:rule位',
        'desc.require' => '请输入:attribute',
        'desc.scalar' => ':attribute应该是字符串',
        'desc.max' => ':attribute长度不能超过:rule位',
        'quotaCard.require' => '请输入:attribute',
        'quotaCard.numeric' => ':attribute应该是数字',
        'quotaCard.egt' => ':attribute应该大于等于:rule',
        'quotaCoin.require' => '请输入:attribute',
        'quotaCoin.numeric' => ':attribute应该是数字',
        'quotaCoin.egt' => ':attribute应该大于等于:rule',
        'updated.require' => '请输入:attribute',
        'updated.integer' => ':attribute应该是整数',
        'updated.egt' => ':attribute应该大于等于:rule',
        'updated.max' => ':attribute长度不能超过:rule位',
        'created.require' => '请输入:attribute',
        'created.integer' => ':attribute应该是整数',
        'created.egt' => ':attribute应该大于等于:rule',
        'created.max' => ':attribute长度不能超过:rule位',
        'deleted.require' => '请输入:attribute',
        'deleted.integer' => ':attribute应该是整数',
        'deleted.egt' => ':attribute应该大于等于:rule',
        'deleted.max' => ':attribute长度不能超过:rule位',
        'page.require' => '请输入:attribute',
        'page.integer' => ':attribute应该是整数',
        'page.egt' => ':attribute应该大于等于:rule',
        'page.max' => ':attribute长度不能超过:rule位',
        'page_size.require' => '请输入:attribute',
        'page_size.integer' => ':attribute应该是整数',
        'page_size.egt' => ':attribute应该大于等于:rule',
        'page_size.max' => ':attribute长度不能超过:rule位',
    ];

    protected $scene = [
        'delete' => ['id' => 'require'],
        'index' => ['page', 'page_size'],
        'read' => ['id' => 'require'],
        'save' => [
            'companyId',
            'name' => 'require',
            'mobile' => 'require',
            'desc',
            'quotaCard' => 'require',
            'quotaCoin' => 'require',
        ],
    ];

    /**
     * 是否是正确的手机号
     * @param $value
     * @return bool|string
     */
    protected function phone($value)
    {
        if(CheckUtil::isPhoneNumber($value)){
            return true;
        }
        return ':attribute应该是正确的手机号码';
    }
}
